package com.bluefox.config;

import com.bluefox.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @program: bluefox-parent
 * @description:
 * @author: Sun Feng
 * @create: 2020-07-17 09:51
 **/
@Slf4j
@Component
public class AuditorConfig implements AuditorAware<String> {
    @Override
    public Optional<String> getCurrentAuditor() {
        String username = SecurityUtils.getAuditorUserName();
        if (username != null){
            return Optional.of(username);
        } else {
            return Optional.of("Anonymous");
        }
    }
}
